artDialog.notice = function (options) {
    var opt = options || {},
        api, aConfig, hide, wrap, top,
        duration = 800;
        
    var config = {
        id: 'Notice',
        left: '100%',
        top: '100%',
        fixed: true,
        drag: false,
        resize: false,
        follow: null,
        lock: false,
        init: function(here){
            api = this;
            aConfig = api.config;
            wrap = api.DOM.wrap;
            top = parseInt(wrap[0].style.top);
            hide = top + wrap[0].offsetHeight;
            
            wrap.css('top', hide + 'px')
                .animate({top: top + 'px'}, duration, function () {
                    opt.init && opt.init.call(api, here);
                });
        },
        close: function(here){
            wrap.animate({top: hide + 'px'}, duration, function () {
                opt.close && opt.close.call(this, here);
                aConfig.close = $.noop;
                api.close();
            });
            
            return false;
        }
    };	
    
    for (var i in opt) {
        if (config[i] === undefined) config[i] = opt[i];
    };
    
    return artDialog(config);
};
$(function(){
	//主体右键菜单
    $('.fileContiner').contextMenu('myMenu1', 
     {
	  bindings: 
	  {
		'fresh': function(t) {
		  window.location.reload();
		},
		'fullscreen': function(t) {
			var docElm = document.documentElement;			
			if (docElm.requestFullscreen) {
				docElm.requestFullscreen();
			}else if (docElm.mozRequestFullScreen) {
				docElm.mozRequestFullScreen();
			} else if (docElm.webkitRequestFullScreen) {
				docElm.webkitRequestFullScreen();
			}
		},
		'uploaded': function(t) {
			//art.dialog.load(loginurl,{id:'upload',title:'测试'});
			art.dialog.notice({
				title: '消息<input type="hidden" id="float-notice">',
				width: 220,// 必须指定一个像素宽度值或者百分比，否则浏览器窗口改变可能导致artDialog收缩
				content: '您有新未读消息',
				icon: 'face-sad',
				time: 5,
			});
		},
		'delete': function(t) {
		  alert('Trigger was '+t.id+'\nAction was Delete');
		}
	  }

    });
	//任务栏右键菜单
    $('.task').die().live('mousedown click',function(e,a){
		if(e.type == "mousedown"){
			if(e.which == 3 || a == 'right'){
				$(this).contextMenu('taskmenu', 
				{
				  bindings: 
				  {
					'task-open': function(t) {
						var id = (t.id).split('-')[1];
						art.dialog.list[id].show();
						$("#"+t.id).removeClass('no-read-msg');
					},
					'task-close': function(t) {
						var id = (t.id).split('-')[1];
						$("#task-"+id).remove();
						art.dialog.list[id].close();
					}
				  }

				});
			}
		}else{
			var id = $(this).attr('id').split('-')[1];
			art.dialog.list[id].show();
			$(this).removeClass('no-read-msg');
		}
	})
	//窗口顶部右键菜单
    $('.aui_title').die().live('mousedown',function(e,a){
		if(e.which == 3 || a == 'right'){
			$(this).contextMenu('topwindowmenu', 
			{
			  bindings: 
			  {
				'topwindow-min': function(t) {
				},
				'topwindow-close': function(t) {
				}
			  }

			});
		}
	})
	//控制桌面图标
	$(".filediv").die().live('mouseenter mouseleave mousedown dblclick',function(e,a){
		if(e.type == 'mouseenter'){
			$(".fileContiner").unbind('click');
			$(this).click(function(){
				$(".file").each(function(){
					$(this).removeClass('select');
				});
				$(this).addClass('select');
			});
		}else if(e.type == 'mouseleave'){
			$(".fileContiner").click(function(){
				$("div.select").removeClass('select');
				$('.msg-icon').popover('hide');
			});
		}else if(e.type == 'dblclick'){
			var id = $(this).attr('id');
			var title = $(this).find('span.title').html();
			var url = $(this).attr('target-url');
			if($(".task_tab #task-"+id).length == 0){
				windows(url,'{id:"'+id+'",title:"'+title+'",width:"65%",height:"75%"}');
			}else{
				art.dialog.list[id].show();
			}
		}else{
			$(".file").each(function(){
				$(this).removeClass('select');
			});
			if(e.which == 3 || a == 'right'){
				$(this).addClass('select');
			}
		}
	});
	//控制桌面图标
	$(".fileframe").die().live('mouseenter mouseleave mousedown dblclick',function(e,a){
		if(e.type == 'mouseenter'){
			$(".fileContiner").unbind('click');
			$(this).click(function(){
				$(".file").each(function(){
					$(this).removeClass('select');
				});
				$(this).addClass('select');
			});
		}else if(e.type == 'mouseleave'){
			$(".fileContiner").click(function(){
				$("div.select").removeClass('select');
				$('.msg-icon').popover('hide');
			});
		}else if(e.type == 'dblclick'){
			var id = $(this).attr('id');
			var title = $(this).find('span.title').html();
			var url = $(this).attr('target-url');
			if($(".task_tab #task-"+id).length == 0){
				windowsframe(url,'{id:"'+id+'",title:"'+title+'",width:"65%",height:"75%"}');
			}else{
				art.dialog.list[id].show();
			}
		}else{
			$(".file").each(function(){
				$(this).removeClass('select');
			});
			if(e.which == 3 || a == 'right'){
				$(this).addClass('select');
			}
		}
	});
	//最小化
	$(".aui_min").live('click',function(){
		var biaoshi = $(this).parents('tbody').find('.windowbiaoshi').attr('id');
		art.dialog.list[biaoshi].hide();
	});
	//最大化
	$(".aui_max").live('click',function(){
		var tbody = $(this).parents('tbody');
		var biaoshi = tbody.find('.windowbiaoshi').attr('id');
		var forward = tbody.find('.aui_main');
		var screenWidth = $(document).width();
		//var screenHeight = $(document).height();
		var left,top,width,height;
		//var perh = (75/screenHeight)*100;
		$(this).toggle(
			function(){
				left = $(this).parents('.aui_outer').parent().css('left');
				top = $(this).parents('.aui_outer').parent().css('top');
				width = forward.css('width');
				height = forward.css('height');
				art.dialog.list[biaoshi].position('0%','0%');
				art.dialog.list[biaoshi].size('100%','100%');
			},
			function(){
				art.dialog.list[biaoshi].position(left,top);
				var per = ((parseInt(width))/screenWidth)*(100)+"%";
				art.dialog.list[biaoshi].size(per,height);
			}
		)
	});
	//聊天主窗口
	$(".chat").unbind('click').click(function(){
		var chat = $(this);
		windowChatContainer(chat.attr('data-url'));		
	});
	$(".chat-group > li > div").die().live('click',function(){
		$(this).toggle(
			function(){
				$(this).removeClass('list_arrow_right').addClass("list_arrow_fire");
				$(this).next().removeClass('hide');
			},function(){
				$(this).removeClass('list_arrow_fire').addClass("list_arrow_right");
				$(this).next().addClass('hide');
			}
		);
	});
	$(".group-members li").die().live('click',function(){
		var li = $(this);
		var role = li.attr('data-role');
		if($(".task_tab #task-chat_with_"+role).length == 0){
			windows(li.attr('data-url')+"/to/"+role,'{id:"chat_with_'+role+'",title:"和'+role+'聊天中...",width:500,height:400}');
		}else{
			art.dialog.list['chat_with_'+role].show();
		}
	});
	$(".emotion").die().live('click',function(){
		var emotion = $(".defaultFacePanel");
		if(emotion.css('display') == "block"){
			emotion.hide();
			return;
		}
		emotion.show();
	});
	$(".defaultFacePanel a").live('click',function(){
		var id = $(this).attr("id");
		$(".rich_editor_div").append("<img src='/M/Public/static/bootstrap/images/emoticons/"+id+".gif'>");
		$(this).parent().hide();
	});
	//消息盒子
	$('.msg-icon,.mail').mouseover(function(){
		$(this).popover('show');
	});
	$(".fileContiner").click(function(){
		$('.msg-icon,.mail').popover('hide');
	});
	$(".manage .setting li").live('click',function(){
		if($(this).attr('class') == "selected") return;
		$(".manage .setting li").each(function(){
			$(this).removeClass('selected');
		});
		$(this).addClass('selected');
		$(".manage .content_right").load($(this).attr('data-url'));
	});
})
//关闭任务栏窗口
function windowClose(t){
	var biaoshi = t.parents('tbody').find('.windowbiaoshi').attr('id');
	$("#task-"+biaoshi).remove();
}
//登录
function windowLogin(url){
	windows(url,'{id:"login",title:"用户登录"}');
}
//登录
function doLogin(formId){
	var self = $("#"+formId);
	$.post(self.attr('action'),self.serialize(),function(json){
		if(json.status == 1){
			art.dialog.list['login'].close();
			window.location.reload();
		}
	})
}
//生成div窗口  istask(boolean) 为是否在任务栏显示 默认为true;
function windows(url,setting,istask){
	if(istask == undefined) istask = true;
	var setting = eval('(' + setting + ')'); //由JSON字符串转换为JSON对象
	setting.title = setting.title+'<input type="hidden" id="'+setting.id+'" class="windowbiaoshi">';
	art.dialog.load(url,setting,false);
	if(istask){
		var taskhtml = '<div class="task" id="task-'+setting.id+'" style="width: 110px;">'+setting.title+'</div>';
		$(".task_tab").append(taskhtml);
	}
	$(".aui_max").unbind('click').trigger('click');
}
//生成frame窗口  istask(boolean) 为是否在任务栏显示 默认为true;
function windowsframe(url,setting,istask){
	if(istask == undefined) istask = true;
	var setting = eval('(' + setting + ')'); //由JSON字符串转换为JSON对象
	setting.title = setting.title+'<input type="hidden" id="'+setting.id+'" class="windowbiaoshi">';
	art.dialog.open(url,setting,false);
	if(istask){
		var taskhtml = '<div class="task" id="task-'+setting.id+'" style="width: 110px;">'+setting.title+'</div>';
		$(".task_tab").append(taskhtml);
	}
	
}
//function windows(url,setting,istask){
//	if(istask == undefined) istask = true;
//	var setting = eval('(' + setting + ')'); //由JSON字符串转换为JSON对象
//	setting.title = setting.title+'<input type="hidden" id="'+setting.id+'" class="windowbiaoshi">';
//	var dialog = art.dialog(setting);
//	if(istask){
//		var taskhtml = '<div class="task" id="task-'+setting.id+'" style="width: 110px;">'+setting.title+'</div>';
//		$(".task_tab").append(taskhtml);
//	}
//	$.ajax({		
//		url:url,
//		success: function (data) {
//			dialog.content(data);
//		},
//		cache: false
//	});
//	$(".aui_max").unbind('click').trigger('click'); 
//}
//聊天
function windowChatContainer(url){
	if(art.dialog.list['main-chat'] == undefined){
		var left = ($(document).width() - 250)+"px";
		windows(url,'{id:"main-chat",title:"员工列表",left:"'+left+'",width:220,resize:false,init:function(){$(".list_group_title").trigger("click");}}',false);
		//$(".main-chat").jScrollPane();
	}else{
		art.dialog.list['main-chat'].show();
	} 
}
